package com.zz.ecommerce.common;

import com.zz.ecommerce.utils.SqlProvider;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

public interface CommonDao<T> {

    @SelectProvider(type = SqlProvider.class, method = "getEportSeq")
    String getEportSeq();

    @SelectProvider(type = SqlProvider.class, method = "getSequenceByName")
    String getSequence(@Param("sequenceName") String sequenceName);

    @DeleteProvider(type = SqlProvider.class, method = "delete")
    int delete(@Param("tableName") String tableName,
               @Param("deleteCondition") String deleteCondition);

    @InsertProvider(type = SqlProvider.class, method = "insert")
    int insert(@Param("tableName") String tableName,
               @Param("insertObj") T insertObj);

    @UpdateProvider(type = SqlProvider.class, method = "update")
    int update(@Param("tableName") String tableName,
               @Param("updateObj") T updateObj,
               @Param("updateCondition") String updateCondition);

    @UpdateProvider(type = SqlProvider.class, method = "updateDmlBean")
    int updateDmlBean(@Param("tableDmlBean") TableDmlBean tableDmlBean);

    @SelectProvider(type = SqlProvider.class, method = "selectCount")
    int count(@Param("tableName") String tableName,
              @Param("qryObj") T qryObj);

    @SelectProvider(type = SqlProvider.class, method = "selectCount")
    int countWhere(@Param("tableName") String tableName,
                   @Param("qryObj") T qryObj,
                   @Param("appendWhere") String appendWhere);

    @SelectProvider(type = SqlProvider.class, method = "selectByPage")
    List<T> page(@Param("tableName") String tableName,
                 @Param("qryObj") T qryObj,
                 @Param("start") final int start,
                 @Param("end") final int end,
                 @Param("sortOrder") String order);

    @SelectProvider(type = SqlProvider.class, method = "selectByPage")
    List<T> pageWhere(@Param("tableName") String tableName,
                      @Param("qryObj") T qryObj,
                      @Param("start") final int start,
                      @Param("end") final int end,
                      @Param("sortOrder") String order,
                      @Param("appendWhere") String appendWhere);

    @SelectProvider(type = SqlProvider.class, method = "selectByPage")
    <T> List<T> qryPageListCustomRowid(@Param("tableName") String tableName,
                                       @Param("qryObj") T t,
                                       @Param("start") final int start,
                                       @Param("end") final int end,
                                       @Param("sortOrder") String order,
                                       @Param("rowid") String rowid);

    @SelectProvider(type = SqlProvider.class, method = "selectByPage")
    List<T> pageWhereCustomRowid(@Param("tableName") String tableName,
                                 @Param("qryObj") T qryObj,
                                 @Param("start") final int start,
                                 @Param("end") final int end,
                                 @Param("sortOrder") String order,
                                 @Param("appendWhere") String appendWhere,
                                 @Param("rowid") String rowid);

    @SelectProvider(type = SqlProvider.class, method = "selectOne")
    T query(@Param("tableName") String tableName,
            @Param("qryObj") T qryObj);

    @SelectProvider(type = SqlProvider.class, method = "selectOne")
    T queryWhere(@Param("tableName") String tableName,
                 @Param("qryObj") T qryObj,
                 @Param("appendWhere") String appendWhere);

    @SelectProvider(type = SqlProvider.class, method = "selectAll")
    List<T> queryAll(@Param("tableName") String tableName,
                     @Param("qryObj") T qryObj,
                     @Param("sortOrder") String order);

    @SelectProvider(type = SqlProvider.class, method = "selectOne")
    <T> T qryOneCommon(@Param("tableName") String tableName, @Param("qryObj") final T t,
                       @Param("sortOrder") String sortOrder);

    @SelectProvider(type = SqlProvider.class, method = "selectAll")
    List<T> queryAllWhere(@Param("tableName") String tableName,
                          @Param("qryObj") T qryObj,
                          @Param("sortOrder") String order,
                          @Param("appendWhere") String appendWhere);

    @Select("select * from ${tableName} where ${whereCondition}")
    List<Map<String, Object>> qryAllByWhere(@Param("tableName") final String tableName,
                                            @Param("whereCondition") final String whereCondition);

    @Select("${sql}")
    List<Map<String, Object>> qrySql(@Param("sql") final String executeSql);


}
